﻿@model ForumTopicPageModel
@using Nop.Web.Extensions;
@using Nop.Web.Models.Boards;
@using Nop.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_Root.cshtml";

    Html.AddTitleParts(Model.Subject);
}
<div class="page forum-topic-page">
    <div class="page-title">
        <h2>@Model.Subject</h2>
    </div>
    <div class="topic-header">
        <div class="topic-options">
            @if (Model.IsCustomerAllowedToEditTopic)
            {
                <a href="@Url.RouteUrl("TopicEdit", new { id = Model.Id })" data-inline="true" data-role="button">@T("Forum.EditTopic")</a>   
            }
            @if (Model.IsCustomerAllowedToDeleteTopic)
            {
                <a href="@Url.RouteUrl("TopicDelete", new { id = Model.Id })" data-inline="true" data-role="button">@T("Forum.DeleteTopic")</a>
            }
            @if (Model.IsCustomerAllowedToMoveTopic)
            {
                <a href="@Url.RouteUrl("TopicMove", new { id = Model.Id })" data-inline="true" data-role="button">@T("Forum.MoveTopic")</a>
            }
            <a href="@Url.RouteUrl("PostCreate", new { id = Model.Id })" data-role="button">@T("Forum.Reply")</a>
        </div>
        <div class="pager upper">
            @{
                var pager = Html.Pager(new PagerModel()
                                           {
                                               PageSize = Model.PostsPageSize,
                                               TotalRecords = Model.PostsTotalRecords,
                                               PageIndex = Model.PostsPageIndex,
                                               ShowTotalSummary = false,
                                               RouteActionName = "TopicSlugPaged",
                                               UseRouteLinks = true,
                                               RouteValues = new RouteValues { id = Model.Id, slug = Model.SeName }
                                           });
            }
            @pager
        </div>
    </div>
    <div class="posts">
        @foreach (var post in @Model.ForumPostModels)
        {
            Html.RenderPartial("_ForumPost", post);
        }
    </div>
</div>
<div class="topic-footer">
    <div class="topic-options">
        @if (Model.IsCustomerAllowedToSubscribe)
        {
            <script type="text/javascript">
                $(function () {
                    $('#watch-topic').click(function () {
                        //show progress
                        $.mobile.showPageLoadingMsg();
                        $.ajax({
                            cache: false,
                            type: 'POST',
                            url: '@Url.RouteUrl("TopicWatch", new { id = Model.Id })',
                            dataType: 'json',
                            success: function (data) {
                                $('#watch-topic').val(data.Text);
                                $('#watch-topic').button("refresh");
                            },
                            complete: function (data) {
                                //hide progress
                                $.mobile.hidePageLoadingMsg();
                            }
                        });
                        return false;
                    });
                });
            </script>
            <input type="button" id="watch-topic" value="@Model.WatchTopicText" />
        }
    </div>
    <div class="pager lower">
        @pager
    </div>
</div>
